<?php


abstract class BaseSitvivienda extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $numhistoria;


	
	protected $terrenopropio;


	
	protected $cantidadper;


	
	protected $adquicesta;


	
	protected $dondeduerme;


	
	protected $dispo_dormir;


	
	protected $inst_roedores;


	
	protected $animales;

	
	protected $aHistoria;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getNumhistoria()
	{

		return $this->numhistoria;
	}

	
	public function getTerrenopropio()
	{

		return $this->terrenopropio;
	}

	
	public function getCantidadper()
	{

		return $this->cantidadper;
	}

	
	public function getAdquicesta()
	{

		return $this->adquicesta;
	}

	
	public function getDondeduerme()
	{

		return $this->dondeduerme;
	}

	
	public function getDispoDormir()
	{

		return $this->dispo_dormir;
	}

	
	public function getInstRoedores()
	{

		return $this->inst_roedores;
	}

	
	public function getAnimales()
	{

		return $this->animales;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = SitviviendaPeer::ID;
		}

	} 
	
	public function setNumhistoria($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->numhistoria !== $v) {
			$this->numhistoria = $v;
			$this->modifiedColumns[] = SitviviendaPeer::NUMHISTORIA;
		}

		if ($this->aHistoria !== null && $this->aHistoria->getNumhistoria() !== $v) {
			$this->aHistoria = null;
		}

	} 
	
	public function setTerrenopropio($v)
	{

		if ($this->terrenopropio !== $v) {
			$this->terrenopropio = $v;
			$this->modifiedColumns[] = SitviviendaPeer::TERRENOPROPIO;
		}

	} 
	
	public function setCantidadper($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->cantidadper !== $v) {
			$this->cantidadper = $v;
			$this->modifiedColumns[] = SitviviendaPeer::CANTIDADPER;
		}

	} 
	
	public function setAdquicesta($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->adquicesta !== $v) {
			$this->adquicesta = $v;
			$this->modifiedColumns[] = SitviviendaPeer::ADQUICESTA;
		}

	} 
	
	public function setDondeduerme($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->dondeduerme !== $v) {
			$this->dondeduerme = $v;
			$this->modifiedColumns[] = SitviviendaPeer::DONDEDUERME;
		}

	} 
	
	public function setDispoDormir($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->dispo_dormir !== $v) {
			$this->dispo_dormir = $v;
			$this->modifiedColumns[] = SitviviendaPeer::DISPO_DORMIR;
		}

	} 
	
	public function setInstRoedores($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->inst_roedores !== $v) {
			$this->inst_roedores = $v;
			$this->modifiedColumns[] = SitviviendaPeer::INST_ROEDORES;
		}

	} 
	
	public function setAnimales($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->animales !== $v) {
			$this->animales = $v;
			$this->modifiedColumns[] = SitviviendaPeer::ANIMALES;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->numhistoria = $rs->getInt($startcol + 1);

			$this->terrenopropio = $rs->getBoolean($startcol + 2);

			$this->cantidadper = $rs->getInt($startcol + 3);

			$this->adquicesta = $rs->getString($startcol + 4);

			$this->dondeduerme = $rs->getString($startcol + 5);

			$this->dispo_dormir = $rs->getString($startcol + 6);

			$this->inst_roedores = $rs->getString($startcol + 7);

			$this->animales = $rs->getString($startcol + 8);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 9; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Sitvivienda object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(SitviviendaPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			SitviviendaPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(SitviviendaPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aHistoria !== null) {
				if ($this->aHistoria->isModified()) {
					$affectedRows += $this->aHistoria->save($con);
				}
				$this->setHistoria($this->aHistoria);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = SitviviendaPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += SitviviendaPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aHistoria !== null) {
				if (!$this->aHistoria->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aHistoria->getValidationFailures());
				}
			}


			if (($retval = SitviviendaPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = SitviviendaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getNumhistoria();
				break;
			case 2:
				return $this->getTerrenopropio();
				break;
			case 3:
				return $this->getCantidadper();
				break;
			case 4:
				return $this->getAdquicesta();
				break;
			case 5:
				return $this->getDondeduerme();
				break;
			case 6:
				return $this->getDispoDormir();
				break;
			case 7:
				return $this->getInstRoedores();
				break;
			case 8:
				return $this->getAnimales();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = SitviviendaPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getNumhistoria(),
			$keys[2] => $this->getTerrenopropio(),
			$keys[3] => $this->getCantidadper(),
			$keys[4] => $this->getAdquicesta(),
			$keys[5] => $this->getDondeduerme(),
			$keys[6] => $this->getDispoDormir(),
			$keys[7] => $this->getInstRoedores(),
			$keys[8] => $this->getAnimales(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = SitviviendaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setNumhistoria($value);
				break;
			case 2:
				$this->setTerrenopropio($value);
				break;
			case 3:
				$this->setCantidadper($value);
				break;
			case 4:
				$this->setAdquicesta($value);
				break;
			case 5:
				$this->setDondeduerme($value);
				break;
			case 6:
				$this->setDispoDormir($value);
				break;
			case 7:
				$this->setInstRoedores($value);
				break;
			case 8:
				$this->setAnimales($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = SitviviendaPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setNumhistoria($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setTerrenopropio($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCantidadper($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setAdquicesta($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setDondeduerme($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setDispoDormir($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setInstRoedores($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setAnimales($arr[$keys[8]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(SitviviendaPeer::DATABASE_NAME);

		if ($this->isColumnModified(SitviviendaPeer::ID)) $criteria->add(SitviviendaPeer::ID, $this->id);
		if ($this->isColumnModified(SitviviendaPeer::NUMHISTORIA)) $criteria->add(SitviviendaPeer::NUMHISTORIA, $this->numhistoria);
		if ($this->isColumnModified(SitviviendaPeer::TERRENOPROPIO)) $criteria->add(SitviviendaPeer::TERRENOPROPIO, $this->terrenopropio);
		if ($this->isColumnModified(SitviviendaPeer::CANTIDADPER)) $criteria->add(SitviviendaPeer::CANTIDADPER, $this->cantidadper);
		if ($this->isColumnModified(SitviviendaPeer::ADQUICESTA)) $criteria->add(SitviviendaPeer::ADQUICESTA, $this->adquicesta);
		if ($this->isColumnModified(SitviviendaPeer::DONDEDUERME)) $criteria->add(SitviviendaPeer::DONDEDUERME, $this->dondeduerme);
		if ($this->isColumnModified(SitviviendaPeer::DISPO_DORMIR)) $criteria->add(SitviviendaPeer::DISPO_DORMIR, $this->dispo_dormir);
		if ($this->isColumnModified(SitviviendaPeer::INST_ROEDORES)) $criteria->add(SitviviendaPeer::INST_ROEDORES, $this->inst_roedores);
		if ($this->isColumnModified(SitviviendaPeer::ANIMALES)) $criteria->add(SitviviendaPeer::ANIMALES, $this->animales);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(SitviviendaPeer::DATABASE_NAME);

		$criteria->add(SitviviendaPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setNumhistoria($this->numhistoria);

		$copyObj->setTerrenopropio($this->terrenopropio);

		$copyObj->setCantidadper($this->cantidadper);

		$copyObj->setAdquicesta($this->adquicesta);

		$copyObj->setDondeduerme($this->dondeduerme);

		$copyObj->setDispoDormir($this->dispo_dormir);

		$copyObj->setInstRoedores($this->inst_roedores);

		$copyObj->setAnimales($this->animales);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new SitviviendaPeer();
		}
		return self::$peer;
	}

	
	public function setHistoria($v)
	{


		if ($v === null) {
			$this->setNumhistoria(NULL);
		} else {
			$this->setNumhistoria($v->getNumhistoria());
		}


		$this->aHistoria = $v;
	}


	
	public function getHistoria($con = null)
	{
		if ($this->aHistoria === null && ($this->numhistoria !== null)) {
						$this->aHistoria = HistoriaPeer::retrieveByPK($this->numhistoria, $con);

			
		}
		return $this->aHistoria;
	}

} 